﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KeywordsMoveFiles400
{
    public class ConfigInfo
    {
        public string FilesPath { set; get; }
        public string SavePath1 { set; get; }
        public string SavePath2 { set; get; }
        public string SavePath3 { set; get; }
        public string SavePath4 { set; get; }

        public string KeywordsFile1 { set; get; }
        public string KeywordsFile2 { set; get; }
        public string KeywordsFile3 { set; get; }
        public string KeywordsFile4 { set; get; }
    }
    public class ConfigMgr
    {
        public static void Save(ConfigInfo obj)
        {
            string fn = Path.Combine(Application.StartupPath, "MoveFiles.cfg");
            string json = JsonConvert.SerializeObject(obj);
            File.WriteAllText(fn, json, Encoding.UTF8);
        }
        public static ConfigInfo Get()
        {
            string fn = Path.Combine(Application.StartupPath, "MoveFiles.cfg");
            try
            {
                if (File.Exists(fn))
                {
                    string json = File.ReadAllText(fn, Encoding.UTF8);
                    var temp = JsonConvert.DeserializeObject<ConfigInfo>(json);
                    if (temp != null) return temp;
                }
            }
            catch
            {
                return new ConfigInfo();
            }
            return new ConfigInfo();
        }
    }
}
